package com.cg.service.impl;

import com.cg.dto.AddLikeDTO;
import com.cg.entity.UserLike;
import com.cg.entity.Video;
import com.cg.mapper.VideoMapper;
import com.cg.result.R;
import com.cg.service.AccountService;
import com.cg.service.ILikeService;
import com.cg.service.IVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 加
 * @since 2025-01-17
 */
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements IVideoService {
    @Autowired
    private IVideoService videoService;
    @Autowired
    private ILikeService likeService;
    @Autowired
    private AccountService accountService;

    @Override
    public R addLike(AddLikeDTO addLikeDTO) {
        UserLike like=new UserLike();
        like.setVideoId(addLikeDTO.getVideoId());
        like.setUserId(accountService.getCurrentUserId());
        like.setContent(videoService.selectContentById(addLikeDTO.getVideoId()));
        likeService.save(like);
        return R.Success("收藏视频成功");
    }

    @Override
    public String selectContentById(Long videoId) {
        Video video=getById(videoId);
        return video.getVideoName();
    }
}
